import pygame
import towers.towerbase as TowerBase
from towers.beam import Beam
from helpers import load_image
from helpers import load_sound_fx
import math
import xml.etree.cElementTree as ET

class Laser(TowerBase.TowerBase):
    
    player = None
    
    name = 'Laser Tower'
    fire_type = 'beam'
    baseRadius = [150, 160, 170, 180, 190, 200, 210, 220, 230, 240]
    baseDamage = [25, 30, 35, 40, 45, 50, 55, 60, 75, 80]
    baseFireRate = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21]
    baseCost = [10, 10, 10, 10, 10]
    baseExperience = [20, 30, 40, 50]
    
    base_energy_cost = [50, 90, 90, 90, 90, 90]
    base_mass_cost   = [50, 90, 90, 90, 90, 90]
    mass_cost   = 0
    energy_cost = 0
    base_shot_mass   = [10, 10, 10, 10, 10, 10]
    base_shot_energy = [10, 10, 10, 10, 10, 10]
    shot_mass   = 0
    shot_energy = 0
    
    #modules_level2 = ['EnergyStorage', 'MassStorage', 'MultiStorage']
    modules_level2 = ['Range', 'FirePower']
    modules_level3 = ['FireRate', 'FirePower', 'Range']
    modules_level4 = ['MassReduction', 'EnergyReduction', 'MultiReduction']
    modules_level5 = ['Special']
    
    exp_shot = 1
    exp_kill = 10
    
    damage = 0
    fireRate = 0
    rotationRate = 0.1    
    radius = 0
    cost = 0
    killCount = 0
    shotCount = 0
    cooldown = 0
    projectile_list = None
    target = None
    ttl = 0
    
    angle = 0
    upgrade_time = 10
    
    def __init__(self, player, rect=None):
        TowerBase.TowerBase.__init__(self)

        self.mass_cost = self.base_mass_cost[0]
        self.energy_cost = self.base_energy_cost[0]
        self.shot_mass = self.base_shot_mass[0]
        self.shot_energy = self.base_shot_energy[0] 

        self.player = player

        # Load graphic for the tower
        pygame.sprite.Sprite.__init__(self)
        self.base_image, self.base_rect = load_image('tower_base.png', -1)
         
        self.image, self.rect = load_image('turret_laser.png', -1)
        self.orig_image = self.image

        #if rect != None:
        #    self.rect = rect
            
        # Projectile list
        self.projectile_list = pygame.sprite.Group()    
            
        # Update current stats
        self.radius = self.baseRadius[0]
        self.damage = self.baseDamage[0]
        self.fireRate = self.baseFireRate[0]
        self.cost = self.baseCost[0]   
    
        # Load sound FX
        self.sound = load_sound_fx('laser_fire.wav')
        
    def get_projectile(self):
        return Beam(self, self.target, 10)
        
    def fire(self):
        pass

    def on_hit(self, target):
        target.health -= self.damage
        if target.health <= 0:
            target.kill()
            self.killCount += 1